﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using Manage_Garage_Car.BusinessLogiclayer;
using System.Data;

namespace Manager_Gara_Car
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : RibbonWindow
    {
        CarStyleBusiness m_carStyleBusiness = new CarStyleBusiness();
        CarBusiness m_carBusiness = new CarBusiness();

        public MainWindow()
        {
            InitializeComponent();
        }

        private void RibbonWindow_Loaded(object sender, RoutedEventArgs e)
        {
            dataGrid1DSHX.ItemsSource = m_carStyleBusiness.GetDataStyleCar().DefaultView;

            //cbxCarStyleDSX.DataContext = m_carStyleBusiness.GetDataStyleCar();
            //dataGrid1DSX.ItemsSource = m_carBusiness.GetDataCar().DefaultView;

            //cbxTypeCarTNBT.DataContext = m_carStyleBusiness.GetDataStyleCar();
            //dataGrid1TNBT.ItemsSource = m_carBusiness.GetDataCar().DefaultView;
        }

        #region Tab DSHX

        private void btnNewDSHX_Click(object sender, RoutedEventArgs e)
        {
            tbxNameCarStyleDSHX.Text = "";
            tbxNameCarStyleDSHX.IsEnabled = true;
            tbxProductCountryDSHX.Text = "";
            tbxProductCountryDSHX.IsEnabled = true;
            tbxNoteDSHX.Text = "None";
            tbxNoteDSHX.IsEnabled = true;

            btnAddDSHX.IsEnabled = true;
            btnFixDSHX.IsEnabled = false;
            btnDeleteDSHX.IsEnabled = false;
        }

        private void btnAddDSHX_Click(object sender, RoutedEventArgs e)
        {
            if (tbxNameCarStyleDSHX.Background == Brushes.Red || tbxProductCountryDSHX.Background == Brushes.Red)
            {
                MessageBox.Show("Vui lòng sửa lại thông tin cho đúng!");
                return;
            }
            
            m_carStyleBusiness.SetDataStyleCar(tbxNameCarStyleDSHX.Text,
                                                tbxProductCountryDSHX.Text,
                                                tbxNoteDSHX.Text);

            dataGrid1DSHX.ItemsSource = m_carStyleBusiness.GetDataStyleCar().DefaultView;
            btnAddDSHX.IsEnabled = false;
            btnDeleteDSHX.IsEnabled = true;
            btnFixDSHX.IsEnabled = true;
        }

        private void btnDeleteDSHX_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btnFixDSHX_Click(object sender, RoutedEventArgs e)
        {

        }

        #endregion

        #region Control Tab DSX

        private void btnNewDSX_Click(object sender, RoutedEventArgs e)
        {
            tbxNameCustomerDSX.Text = "";
            tbxNameCustomerDSX.IsEnabled = true;
            tbxNumberPhoneDSX.Text = "";
            tbxNumberPhoneDSX.IsEnabled = true;
            tbxNumberPlateDSX.Text = "";
            tbxNumberPlateDSX.IsEnabled = true;
            tbxAddressDSX.Text = "";
            tbxAddressDSX.IsEnabled = true;
            tbxEmailDSX.Text = "";
            tbxEmailDSX.IsEnabled = true;

            btnAddDSX.IsEnabled = true;
            btnDeleteDSX.IsEnabled = false;
            btnFixDSX.IsEnabled = false;
        }

        private void btnAddDSX_Click(object sender, RoutedEventArgs e)
        {
            m_carBusiness.SetDataCar(tbxNumberPlateDSX.Text,
                                    tbxNameCustomerDSX.Text,
                                    ((DataRowView)cbxCarStyleDSX.SelectedItem).Row[0].ToString(),
                                    tbxAddressDSX.Text,
                                    tbxNumberPhoneDSX.Text,
                                    tbxEmailDSX.Text,
                                    Convert.ToDouble(tbxDebitDSX.Text));

            btnAddDSX.IsEnabled = false;
            btnDeleteDSX.IsEnabled = true;
            btnFixDSX.IsEnabled = true;
            dataGrid1DSX.ItemsSource = m_carBusiness.GetDataCar().DefaultView;
        }

        private void btnDeleteDSX_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btnFixDSX_Click(object sender, RoutedEventArgs e)
        {

        }

        #endregion

        #region Control Tab TNBT

        private void btnNewTNBT_Click(object sender, RoutedEventArgs e)
        {
            tbxNameCustomerTNBT.Text = "";
            tbxNumberPhoneTNBT.Text = "";
            tbxNumberPlateTNBT.Text = "";
            tbxAddressTNBT.Text = "";
            tbxEmailTNBT.Text = "";

            btnAddTNBT.IsEnabled = true;
        }

        private void btnAddTNBT_Click(object sender, RoutedEventArgs e)
        {
        }

        #endregion
        
    }
}
